<script>
import ValueWithInput from '../ValueWithInput/WithSelector2.vue'
import { getSchool } from "@/api/basic"
import { value } from '@/utils/kris_utils'
export default {
    components:{
        ValueWithInput
    },
    computed:{
        attrs(){
            let attrs = {...this.$attrs}
            attrs['fetchDataFn'] = this.fetchSchools
            return attrs
        },
        listeners(){
            return this.$listeners
        },
    },
    methods:{
        async fetchSchools(kw){
            let params = {
                search:kw
            }

            let result = await getSchool(params)
                .catch(err => {
                    throw new Error('获取学校选项失败')
                })

            if(result.code !== 200 || !Array.isArray(result.data))
                throw new Error(value(result,'message','获取学校选项失败'))

            return result.data.map(item => {
                return {
                    label:item.school_name,
                    value:item.id
                }
            })
        }
    }
}
</script>

<template>
    <ValueWithInput 
        v-on="listeners"
        v-bind="attrs"
    />
</template>